

public class algo {
	
	public static void nod ()
	{
	int i, min, max, a, b, temp, iter=0;
	max=(int)(Math.random()*2000000000);
	min=(int)(Math.random()*2000000000);
	System.out.printf("%d \t", max);
	System.out.printf("%d \t", min);
	
	long before = System.currentTimeMillis(); 
	if ((min==1) || (max==1))
	{System.out.println("1\t");
	return;}
	
	if (min==max)
	{System.out.print(min);
	return;}
	
	if (min>max)
	{temp=max;
	max=min;
	min=temp;}
	
	a=min; b=max;
	i=2;
	while (i<=Math.sqrt(min))
	{
		iter++;
		if (min%i==0 && max%i==0)
		{min=min/i;
		max=max/i;}
		else i++;
	}
	long after = System.currentTimeMillis(); 
	long diff = after - before;
	if ((i=a/min)==(b/max))
	{System.out.printf(" %d \t", i);
	System.out.printf("%.10f\t", diff/1e3);
	System.out.printf(" %d \n", iter);
	return;}
	else 
		System.out.println("error!\n");
	return;
	}
	
public static void main(String [] args)
{
	System.out.print("Number 1\t"+"Number 2\t"+"NOD\t"+"Time\t"+"the number of iterations\n");
	for (int i=0; i<10; i++)
	{
		algo.nod();
	}
	
	return;
	
}
	
}
	

